﻿using System;
using NUnit.Framework;
using Smartkernel;

namespace Smartkernel.NUnitTest.
{
    [Category("Core")]
    [TestFixture]
    public class SmartActionTest
    {
        [Test]
        public void Test()
        {
            //【01】判断是不是会引发异常（涉及方法：IsInvokeFail）
            Assert.AreEqual(SmartAction.IsInvokeFail(delegate { throw new Exception(); }), true);
            Assert.AreEqual(SmartAction.IsInvokeFail(delegate { }), false);

            //【02】执行时间的测试（涉及方法：ExecuteTime）
            Assert.AreEqual(SmartAction.ExecuteTime(delegate { Convert.ToInt32("2008"); }, 200000).TotalMilliseconds > SmartAction.ExecuteTime(delegate { Convert.ToInt32("2008"); }, 100000).TotalMilliseconds, true);

            //【03】循环器的测试（涉及方法：ForCirculator）
            int i = 0;
            SmartAction.ForCirculator(delegate { i++; }, 3);
            Assert.AreEqual(i, 3);
        }
    }
}
